home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / vprintf.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.2 KB  |  138 lines

  1. /*
  2.  * Copyright (c) 1991 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator   or   Software.Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie the rights
  23.  * to redistribute these changes.
  24.  */
  25. /*
  26.  * varargs versions of printf routines
  27.  *
  28.  **********************************************************************
  29.  * HISTORY
  30.  * $Log: vprintf.c,v $
  31.  * Revision 1.1.1.1  1993/05/21  14:52:19  cgd
  32.  * initial import of CMU's SUP to NetBSD
  33.  *
  34.  * Revision 2.5  89/09/08  18:15:55  mbj
  35.  *     Use _doprnt() for the Multimax (an "old" architecture).
  36.  *     [89/09/08            mbj]
  37.  * 
  38.  * Revision 2.4  89/08/03  14:40:10  mja
  39.  *     Add vsnprintf() routine.
  40.  *     [89/07/12            mja]
  41.  * 
  42.  *     Terminate vsprintf() string with null byte.
  43.  *     [89/04/21            mja]
  44.  * 
  45.  *     Change to use new hidden name for _doprnt on MIPS.
  46.  *     [89/04/18            mja]
  47.  * 
  48.  * Revision 2.3  89/06/10  14:13:43  gm0w
  49.  *     Added putc of NULL byte to vsprintf.
  50.  *     [89/06/10            gm0w]
  51.  * 
  52.  * Revision 2.2  88/12/13  13:53:17  gm0w
  53.  *     From Brad White.
  54.  *     [88/12/13            gm0w]
  55.  ************************************************************
  56.  */
  57.  
  58. #include <stdio.h>
  59. #include <varargs.h>
  60.  
  61. #ifdef DOPRINT_VA
  62. /* 
  63.  *  system provides _doprnt_va routine
  64.  */
  65. #define    _doprnt    _doprnt_va
  66. #else
  67. /*
  68.  * system provides _doprnt routine
  69.  */
  70. #define _doprnt_va _doprnt
  71. #endif
  72.  
  73.  
  74. #ifdef NEED_VPRINTF
  75. int
  76. vprintf(fmt, args)
  77.     char *fmt;
  78.     va_list args;
  79. {
  80.     _doprnt(fmt, args, stdout);
  81.     return (ferror(stdout) ? EOF : 0);
  82. }
  83.  
  84. int
  85. vfprintf(f, fmt, args)
  86.     FILE *f;
  87.     char *fmt;
  88.     va_list args;
  89. {
  90.     _doprnt(fmt, args, f);
  91.     return (ferror(f) ? EOF : 0);
  92. }
  93.  
  94. int
  95. vsprintf(s, fmt, args)
  96.     char *s, *fmt;
  97.     va_list args;
  98. {
  99.     FILE fakebuf;
  100.  
  101.     fakebuf._flag = _IOSTRG+_IOWRT;    /* no _IOWRT: avoid stdio bug */
  102.     fakebuf._ptr = s;
  103.     fakebuf._cnt = 32767;
  104.     _doprnt(fmt, args, &fakebuf);
  105.     putc('\0', &fakebuf);
  106.     return (strlen(s));
  107. }
  108. #endif    /* NEED_VPRINTF */
  109.  
  110. #if    defined(NEED_VSNPRINTF) || defined(NEED_VPRINTF)
  111. int
  112. vsnprintf(s, n, fmt, args)
  113.     char *s, *fmt;
  114.     va_list args;
  115. {
  116.     FILE fakebuf;
  117.  
  118.     fakebuf._flag = _IOSTRG+_IOWRT;    /* no _IOWRT: avoid stdio bug */
  119.     fakebuf._ptr = s;
  120.     fakebuf._cnt = n-1;
  121.     _doprnt(fmt, args, &fakebuf);
  122.     fakebuf._cnt++;
  123.     putc('\0', &fakebuf);
  124.     if (fakebuf._cnt<0)
  125.         fakebuf._cnt = 0;
  126.     return (n-fakebuf._cnt-1);
  127. }
  128. #endif    /* NEED_VPRINTF || NEED_VSNPRINTF */
  129.  
  130. #ifdef _ABI_SOURCE
  131. int
  132. vsnprintf(char *s, int n, char *fmt, va_list args)
  133. {
  134.     /*XXX this needs work to emulate expected behavior */
  135.     return vsprintf (s, fmt, args);
  136. }
  137. #endif
  138.